/* This file is part of SpaceSim.
 
 SpaceSim is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SpaceSim is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SpaceSim.  If not, see <http://www.gnu.org/licenses/>. */

#include "time.h"

sf::Clock Time::Clock;
sf::Clock Time::FPSClock;
float Time::UpdateTime = 0;
float Time::InGameTime = 0;

void Time::Update() {
	UpdateTime = FPSClock.GetElapsedTime();
	FPSClock.Reset();
	InGameTime += UpdateTime;
}

Date::Date() {
	Year = 2000;
	Month = 1;
	Day = 1;
}

Date::Date(int _year, int _month, int _day) {
	Year = _year;
	Month = _month;
	Day = _day;
}

int Time::DateToDays(int year, int month, int day) {
	return 367*year - 7 * ( year + (month+9)/12 ) / 4 + 275*month/9 + day - 730530;
}

int Time::DateToDays(Date date) {
	int year = date.GetYear();
	int month = date.GetMonth();
	int day = date.GetDay();
	return 367*year - 7 * ( year + (month+9)/12 ) / 4 + 275*month/9 + day - 730530;
}

Date Time::GetDate() {
	return Date(2000, 1, 1) + (InGameTime * 0.01);
}

float Time::GetDay() {
	return (InGameTime * 0.01);	// one in-game day is 100 seconds
}